﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Ext.Net;

public partial class SYS_POPEDOM_Sys_Param_Manage : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            AddPopWin();
        }
    }

    //添加弹出窗口
    private void AddPopWin()
    {
        string url = "";
        url = G_Url_allstring + "/SYS_POPEDOM/Sys_Param_Edit.aspx";
        String tabid = Request.QueryString["tabid"];
        extBtn_Add.Listeners.Click.Handler = "popfortab(GridPanel1,'" + url + "','ObjId','Add',0,'','" + tabid + "','系统参数定义',1);";
        extBtn_Edit.Listeners.Click.Handler = "popfortab(GridPanel1,'" + url + "','PARAMETER_ID','PARAMETER_ID',0,'','" + tabid + "','系统参数修改',2)";
        GridPanel1.Listeners.RowDblClick.Handler = "popfortab(GridPanel1,'" + url + "','PARAMETER_ID','PARAMETER_ID',rowIndex,'','" + tabid + "','系统参数修改',3)";
    }
    protected void OnStoreRefreshData(object sender, StoreRefreshDataEventArgs e)
    {
        BindData();
    }
    //绑定列表数据
    private void BindData()
    {
        DataTable dt = CommonLib.BLL.SYS_PARAMETER.GetList(" DEL_FLAG = 0 ", " PARAMETER_ID ").Tables[0];
        this.Store1.DataSource = dt;
        this.Store1.DataBind();
    }

    //删除部门
    protected void DelParam(object sender, DirectEventArgs e)
    {
        int nCount = 0;
        RowSelectionModel sm = this.GridPanel1.SelectionModel.Primary as RowSelectionModel;
        nCount = sm.SelectedRows.Count;
        if (nCount == 0)
        {
            X.Msg.Alert("系统提示", "请先选择要删除的记录！").Show();
            return;
        }

        X.Msg.Confirm("系统提示", "是否删除选中行?", new MessageBoxButtonsConfig
        {
            Yes = new MessageBoxButtonConfig
            {
                Handler = "Ext.net.DirectMethods.DoDelParam();",
                Text = "是"
            },
            No = new MessageBoxButtonConfig
            {
                Text = "否"
            }
        }).Show();

    }

    //删除菜单
    [DirectMethod]
    public void DoDelParam()
    {
        RowSelectionModel sm = this.GridPanel1.SelectionModel.Primary as RowSelectionModel;
        foreach (SelectedRow row in sm.SelectedRows)
        {
            //if (CommonLib.BLL.SYS_DEPT.GetRecorderCount(" trim(parent_id) ='" + row.RecordID.Trim() + "'") > 0)
            //{
            //    Ext.Msg.Alert("系统提示", "节点被引用不能删除！").Show();
            //    continue;
            //}
            CommonLib.Model.SYS_PARAMETER oParam = CommonLib.BLL.SYS_PARAMETER.GetModel(row.RecordID.Trim());
            oParam.DEL_FLAG = 1;
            CommonLib.BLL.SYS_PARAMETER.Update(oParam);
        }

        BindData();

    }

    //刷新Grid
    protected void OnRefresh(object sender, DirectEventArgs e)
    {
        BindData();
    }
}
